An algorithm to establish the arrival directions of CRs from extragalactic sources