You COULD:
REPEAT
Do a pick
Get pickedX() pickedY() pickedZ()
UNTIL pickedlength > specified_distance
Basically, do a pick. If it's below a certain length, redo the pick from the picked() co-ords. That way, It keeps picking through items, until the one you want is found, or until the length of pick is too great that nothing else will be found.
REPEAT
Do a pick
Get pickedX() pickedY() pickedZ()
UNTIL pickedlength > specified_distance
Basically, do a pick. If it's below a certain length, redo the pick from the picked() co-ords. That way, It keeps picking through items, until the one you want is found, or until the length of pick is too great that nothing else will be found.