Filter eligibility before sorting expiry
Synthetic rule: use the eligible package with the earliest unusable timestamp; ties use package ID. Eligibility requires the selected service, positive available sessions and a session start before expiry. A package that expires sooner but excludes the service must not win.
| Package | Scope / available | Unusable from | Selection |
|---|---|---|---|
| P-E1 | Service B / 3 | 16 Oct 00:00 | Exclude: wrong service |
| P-E2 | Service A / 2 | 18 Oct 00:00 | Select one session |
| P-E3 | Service A / 5 | 22 Oct 00:00 | Keep available |
Record the source of the held session
- Filter by member, service, positive available balance and start-time validity.
- Order eligible packages by expiry and the documented tie rule.
- Hold one session from P-E2 and record its package ID on the booking.
If the chosen package changes before allocation, recalculate the eligible set; do not create a negative balance.
How many available sessions remain in P-E2 after one booking?
Show the worked answer
One is available and one is held. P-E1 keeps three because it cannot fund service A.
Returning a cancelled session should reference P-E2, rather than choosing the earliest package again.