Shipment States
The system defines five states in theEstadoEnvio enum (svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/enums/EstadoEnvio.java:3):
State Definitions
PENDIENTE (Pending)
PENDIENTE (Pending)
Initial state when a shipment is created.Characteristics:Available Actions:
- Awaiting vehicle assignment
- Can be canceled
- No tracking code assigned yet (auto-generated on creation)
- 4-digit delivery password created
- Assign vehicle plate (transitions to EN_TRANSITO)
- Cancel shipment (transitions to CANCELADO)
EN_TRANSITO (In Transit)
EN_TRANSITO (In Transit)
Shipment is assigned to a vehicle and in transit to destination.Characteristics:Available Actions:
- Vehicle plate assigned
- Cannot be canceled
- Package is physically moving between branches
- Mark as available for pickup (transitions to DISPONIBLE)
DISPONIBLE (Available for Pickup)
DISPONIBLE (Available for Pickup)
Package arrived at destination branch and ready for recipient pickup.Characteristics:Available Actions:
- Physically at destination branch
- Recipient can pick up with tracking code + password
- Waiting for final delivery
- Deliver package (transitions to ENTREGADO)
ENTREGADO (Delivered)
ENTREGADO (Delivered)
Package successfully delivered to recipient.Characteristics:Available Actions:
- Delivery password validated
fechaEntregatimestamp recorded- Final successful state
- No further transitions possible
- None (terminal state)
CANCELADO (Canceled)
CANCELADO (Canceled)
Shipment canceled before entering transit.Characteristics:Available Actions:
- Only possible from PENDIENTE state
- Cannot be reversed
- Typically due to sender request or payment issues
- None (terminal state)
State Transition Diagram
Allowed Transitions
The system enforces strict state transition rules inEnvioServiceImpl (svc-envio-encomienda/src/main/java/org/jchilon3mas/springcloud/svc/envio/encomienda/servicios/Impl/EnvioServiceImpl.java:292):
Transition Table
| From State | To State | Allowed | Triggered By | API Endpoint |
|---|---|---|---|---|
| PENDIENTE | EN_TRANSITO | ✅ Yes | Assign vehicle plate | POST /api/v1/envios/asignar-placa |
| PENDIENTE | CANCELADO | ✅ Yes | Cancel request | PUT /api/v1/envios/{id}/cancelar |
| EN_TRANSITO | DISPONIBLE | ✅ Yes | Arrives at branch | PUT /api/v1/envios/{id}/disponible |
| DISPONIBLE | ENTREGADO | ✅ Yes | Recipient pickup | POST /api/v1/envios/retirar |
| EN_TRANSITO | CANCELADO | ❌ No | - | - |
| DISPONIBLE | CANCELADO | ❌ No | - | - |
| ENTREGADO | (any) | ❌ No | Terminal state | - |
| CANCELADO | (any) | ❌ No | Terminal state | - |
State Transition APIs
1. Create Shipment (Initial State)
Endpoint:POST /api/v1/envios
Initial State: PENDIENTE
2. Assign Vehicle (PENDIENTE → EN_TRANSITO)
Endpoint:POST /api/v1/envios/asignar-placa
- Shipment must be in
PENDIENTEstate - Plate format:
ABC-123(3-4 alphanumeric characters, hyphen, 3-4 characters) - Plate cannot already be assigned
3. Mark Available (EN_TRANSITO → DISPONIBLE)
Endpoint:PUT /api/v1/envios/{id}/disponible
- Must be in
EN_TRANSITOstate - Typically called when package physically arrives at destination branch
4. Deliver Package (DISPONIBLE → ENTREGADO)
Endpoint:POST /api/v1/envios/retirar
- Must be in
DISPONIBLEstate - Delivery password must match exactly (4 digits)
- Sets
fechaEntregato current timestamp
5. Cancel Shipment (PENDIENTE → CANCELADO)
Endpoint:PUT /api/v1/envios/{id}/cancelar
- Only allowed from
PENDIENTEstate - Cannot cancel once vehicle is assigned
Semantic Synchronization
Every state change is automatically synchronized to the semantic graph:Common State Scenarios
Happy Path
Early Cancellation
Invalid Transition Attempts
Tracking State History
Currently, the system only stores the current state. To track history, you could:Option 1: Query Semantic Graph by Date
Search for all shipments that changed state on a specific date:Option 2: Add State History Entity
Querying by State
REST API
Semantic Search
SPARQL Query
Best Practices
Always validate state
Check current state before attempting transitions
Handle transition errors
Catch
IllegalStateException and inform users clearlyLog state changes
Include timestamps and user info for audit trails
Notify stakeholders
Send emails/SMS on key transitions (DISPONIBLE, ENTREGADO)
Next Steps
Creating Shipments
Learn to create shipments via API
Semantic Search
Query shipments by state naturally
Setup Guide
Configure the system
Ontology Reference
How states are represented in RDF