I have written code that exactly does this (although a lot more complex). I use the "Validate Line" function in a client script that calculates the price and sets the rate and amount. If done right, it will show the correct price in the cart. Keep in mind that you will need to create a similar script in the UI if you set up orders manually as well. Also, you will need to have the product page calculate this, if desired, since this occurs before the line is validated (it is really just for show).