Here's one way, assuming you're picking the "n" nearest Object B to Object A and there are multiple instances of A and B:
Give B the instance boolean "isPicked" and set to false as default.
1. Pick instance of Object A (using whatever criteria you want)
---System: Repeat "n" times
----- Object B isPicked is false, Object B: pick nearest B to (A.X, A.Y): Set isPicked to true
2. Object B: isPicked is true: do your thing.