From the sounds of it your starting point is correct the logic should be along the lines of;
while (stuff in backpack is less than the stuff that needs to be picked up)
if there is somthing on the intersection I am on then
put it in backpack
endif
move forward
end while
As for how to put that in code would you be able to figure that out or would you like my to edit with something that would compile?