1
2
3
4
5
6
7
8
9
10
11
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
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
105
106
107
108
109
110
111
112 shipment.getSender().getBankAccount().withdrawFromBalance(fine);
113 shipment.getReceiver().getBankAccount().addToBalance(fine);
114
115
116 }
117 return true;
118 }
119 return false;
120 }
121 }