In this paper we present an approach to planning with prioritized goal states. To describe the preference ordering on goal states, we make use of ranked knowledge bases which induce a partial preference ordering on plans. We show how an optimal plan can be computed by assigning an integer value to each state in an appropriate manner. We also show how plan optimality can be tested in a similar fashion. Our implementation is based on Metric-FF, one of the fastest existing planning systems. A first empirical evaluation shows very promising results.