Use Case
Given information about passengers and the flights they are booked on and alternative flights, attempt to rebook passengers when their flight is cancelled. Higher priority flyers should get earlier alternative flights where possible. Assume all the flights are non-stop for this challenge.
The Rules

  1. Passengers must only be rebooked on to alternative flights if there is room.
  2. Higher priority passengers must be rebooked onto the earlier flights
  3. The alternative flight must depart from the same airport as the cancelled flight.
  4. The alternative flight must land at the destination airport of the cancelled flight
  5. The alternative flight must depart after the cancelled flight’s original departure time.
  6. Flight status must be scheduled or cancelled or full
  7. Priority must be determined by status (in the order gold, silver, bronze, other) and miles flown in the event of tie.

Here is the core rule sheet that does most of the work:

The implementation looks like this:

A key technique used here is the ->first operator applied to the collection or flights sorted by ascending departure time and to the delayed passengers sorted by decreasing priority. Note that this rule sheet is marked as "iterate" so it will keep going until no more passengers can be rebooked.

See the attached document for more details (including the scope section which is a key part of this rule sheet)