Preparing your design workspace

Loading the problem and your saved attempt…

Design a Package Locker System

Model a city's self-service package lockers: find nearby stations with room, allocate a compartment by a replaceable rule, deposit with a one-time pickup code, pick up, expire, and keep one station correct when couriers and customers use it at the same time.

Design the objects for a network of self-service package lockers, then implement the core of one locker station.

For this exercise, assume a delivery company runs a few hundred locker stations across a city. Each station has a fixed location, given as x and y coordinates in kilometres, and between 20 and 200 numbered compartments, each small, medium or large.

Every package is small, medium or large and fits a compartment of its own size or larger.

The journey has three parts. 1. Locate. Given a customer's location and a package size, list the stations within 5 km that currently have a free compartment that fits, nearest first, with ties broken by station ID. This is advice only and holds nothing. 2. Allocate and deposit.

When the delivery system assigns a package to a station, it gives the package ID, size and customer ID, and one free compartment is reserved for the package. The allocation rule is: the smallest compartment size that fits, then the lowest compartment number of that size. If nothing fits, the allocation is refused.

Asking again for a package that already holds a compartment returns that compartment. A courier can cancel a reservation before depositing, which frees the compartment.

When the courier deposits the package, a 6-digit pickup code is created that is unique among the station's active codes and valid for exactly 3 days, and a notifier is asked to send it to the customer. 3. Pick up. A customer enters a code at the station.

A valid, unexpired code opens that package's compartment, the package is marked picked up, and the compartment becomes free. A wrong or expired code opens nothing.

A package that isn't picked up within 3 days expires: its code stops working, and staff later remove expired packages, which frees their compartments.

Time comes from an injected clock, and code generation and notification are injected dependencies. Couriers, customers and staff can use a station at the same moment. Payments, returns, orders with several packages, door hardware faults, persistence and user interfaces are out of scope.

Clarify the requirements, design the objects, interfaces and interactions, then implement allocation, cancel, deposit, pickup and removal of expired packages for one station in memory.