public RouteSpecification build( Location origin, Location destination, Date earliestDeparture, Date deadline )
throws CannotCreateRouteSpecificationException
{
if( origin == destination )
{
throw new CannotCreateRouteSpecificationException( "Origin location can't be same as destination location." );
}
Date endOfToday = new DateMidnight().plusDays( 1 ).toDate();
if( deadline.before( endOfToday ) )
{
throw new CannotCreateRouteSpecificationException( "Arrival deadline is in the past or Today." +
"\nDeadline " + deadline +
"\nToday (midnight) " + endOfToday );
}
if( deadline.before( earliestDeparture ) )
{
throw new CannotCreateRouteSpecificationException( "Deadline can't be before departure:" +
"\nDeparture " + earliestDeparture +
"\nDeadline " + deadline );
}
ValueBuilder<RouteSpecification> routeSpec = vbf.newValueBuilder( RouteSpecification.class );