IModel<CargoDTO> cargoModel = new CommonQueries().cargo( trackingId );
CargoDTO cargo = cargoModel.getObject();
Delivery delivery = cargo.delivery().get();
RouteSpecification routeSpecification = cargo.routeSpecification().get();
final RoutingStatus routingStatus = delivery.routingStatus().get();
Boolean isMisrouted = routingStatus == RoutingStatus.MISROUTED;
add( new PrevNext( "prevNext", CargoDetailsPage.class, trackingId ) );
add( new Label( "trackingId", trackingId ) );
add( new Label( "origin", cargo.origin().get().getString() ) );
add( new Label( "destination", routeSpecification.destination()
.get()
.getString() ).add( new CorrectColor( isMisrouted ) ) );
add( new Label( "deadline", Model.of( routeSpecification.arrivalDeadline().get() ) ) );
add( new Label( "routingStatus", routingStatus.toString() ).add( new ErrorColor( isMisrouted ) ) );
add( new LinkPanel( "changeDestination", ChangeDestinationPage.class, trackingId, "Change destination" ) );
if( routingStatus == RoutingStatus.NOT_ROUTED )
{
add( new LinkPanel( "routingAction", RouteCargoPage.class, trackingId, "Route" ) );