if( !plannedCarrierMovement.loadLocation().get().equals( c.loadLocation ) )
{
newDelivery.isMisdirected().set( true );
newDelivery.nextHandlingEvent().set( null );
cargo.delivery().set( newDeliveryBuilder.newInstance() );
throw new CargoMisdirectedException( c.loadEvent, "Itinerary expected load in "
+ plannedCarrierMovement.loadLocation()
.get()
.getString() );
}
// Unexpected carrier
if( !plannedCarrierMovement.voyage().get().equals( c.voyage ) )
{
newDelivery.isMisdirected().set( true );
cargo.delivery().set( newDeliveryBuilder.newInstance() );
// ...Expected arrival location - should we accept this?
if( plannedCarrierMovement.unloadLocation()
.get()
.equals( carrierMovement.arrivalLocation().get() ) )
{
throw new CargoMisdirectedException( c.loadEvent, c.itinerary, "Cargo is heading to expected arrival location "
+ plannedCarrierMovement.unloadLocation()
.get() + " but on unexpected voyage "
+ c.voyage
.toString() + ". Notify shipper to unload unexpected cargo in next port." );
}
throw new CargoMisdirectedException( c.loadEvent, c.itinerary, "Itinerary expected load onto voyage "
+ plannedCarrierMovement.voyage()
.get() );
}
// Unexpected carrier destination
if( !plannedCarrierMovement.unloadLocation().get().equals( carrierMovement.arrivalLocation().get() ) )
{
newDelivery.isMisdirected().set( true );
cargo.delivery().set( newDeliveryBuilder.newInstance() );
throw new CargoMisdirectedException( c.loadEvent, "Itinerary expects voyage " + c.voyage.toString()
+ " to arrive in " + plannedCarrierMovement.unloadLocation()
.get() + " but carrier is now going to "
+ carrierMovement.arrivalLocation().get() );
}