View Javadoc

1   /*
2    * @(#) ShipmentFineHandlerStock.java Jan 27, 2005
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  package nl.tudelft.simulation.supplychain.handlers;
14  
15  import java.io.Serializable;
16  
17  import nl.tudelft.simulation.dsol.experiment.TimeUnit;
18  import nl.tudelft.simulation.dsol.experiment.TimeUnitInterface;
19  import nl.tudelft.simulation.logger.Logger;
20  import nl.tudelft.simulation.supplychain.actor.SupplyChainActor;
21  import nl.tudelft.simulation.supplychain.content.Shipment;
22  import nl.tudelft.simulation.supplychain.stock.StockInterface;
23  
24  /***
25   * A stocking Shipment handler where a check is performed whether the shipment
26   * was delivered on time. If not, a fine is imposed.
27   * <p>
28   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
29   * Delft, the Netherlands. All rights reserved.
30   * 
31   * See for project information <a href="http://www.simulation.tudelft.nl/">
32   * www.simulation.tudelft.nl </a>.
33   * 
34   * The source code and binary code of this software is proprietary information
35   * of Delft University of Technology.
36   * 
37   * @author <a
38   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
39   *         van Houten </a>
40   * @version $Revision: 1.2 $ $Date: 2005/04/08 12:00:56 $
41   * @since 1.0.22
42   */
43  public class ShipmentFineHandlerStock extends ShipmentHandlerStock
44  {
45  	/*** the serial version uid */
46  	private static final long serialVersionUID = 11L;
47  
48  	/*** the maximum time out for a shipment */
49  	private double maximumTimeOut = 0.0;
50  
51  	/*** the margin for the fine */
52  	private double fineMarginPerDay = 0.0;
53  
54  	/*** the fixed fine */
55  	private double fixedFinePerDay = 0.0;
56  
57  	/***
58  	 * constructs a new ShipmentFineHandlerStock
59  	 * 
60  	 * @param owner the owner
61  	 * @param stock the stock
62  	 * @param maximumTimeOut the time out
63  	 * @param fineMarginPerDay the fine margin per day
64  	 * @param fixedFinePerDay the fixed fine per day
65  	 */
66  	public ShipmentFineHandlerStock(final SupplyChainActor owner,
67  			final StockInterface stock, final double maximumTimeOut,
68  			final double fineMarginPerDay, final double fixedFinePerDay)
69  	{
70  		super(owner, stock);
71  		this.maximumTimeOut = maximumTimeOut;
72  		this.fineMarginPerDay = fineMarginPerDay;
73  		this.fixedFinePerDay = fixedFinePerDay;
74  	}
75  
76  	/***
77  	 * @see nl.tudelft.simulation.content.HandlerInterface#handleContent(java.io.Serializable)
78  	 */
79  	public boolean handleContent(final Serializable content)
80  	{
81  		if (super.handleContent(content))
82  		{
83  			Shipment shipment = (Shipment) content;
84  			double time = shipment.getSender().getSimulatorTime();
85  			if ((time > shipment.getOrder().getDeliveryDate())
86  					&& (time < shipment.getOrder().getDeliveryDate()
87  							+ this.maximumTimeOut))
88  			{
89  				// YES!! we can fine! Finaly we earn some money
90  				double day = 1.0;
91  				try
92  				{
93  					day = TimeUnit.convert(1.0, TimeUnitInterface.DAY,
94  							this.owner.getSimulator());
95  				} catch (Exception exception)
96  				{
97  					Logger.severe(this, "handleContent", exception);
98  				}
99  
100 				double fine = ((shipment.getOrder().getDeliveryDate() - time) / day)
101 						* (this.fixedFinePerDay + this.fineMarginPerDay
102 								* shipment.getOrder().getPrice());
103 
104 				// we are pragmatic
105 				// send the bill for the fine
106 
107 				/*
108 				 * Bill bill = new Bill(super.owner, shipment.getSender(),
109 				 * shipment.getInternalDemandID(), shipment.getOrder(),
110 				 * super.owner.getSimulatorTime() + (14.0 * day), fine, "FINE");
111 				 */
112 				shipment.getSender().getBankAccount().withdrawFromBalance(fine);
113 				shipment.getReceiver().getBankAccount().addToBalance(fine);
114 
115 				// super.owner.sendContent(bill, 0.0);
116 			}
117 			return true;
118 		}
119 		return false;
120 	}
121 }