Write your logic in end routine.
After that make use of semantic groups.In that select service order number.This will actually help you to bind the data together of same service order number.
So in case if you have any item of a particular service order number in another package,then automatically package size gets increased and it processes the data in same package,
Hope this solves your issue.
Regards,
AL