You've probably seen me answer a lot of questions with "enumerate the entity collection". This resource explains the details and provides a working script example. Later on I might upload a fully working module that shows it in action.
HTH,
DC
HTH,
DC