There are many ways of using meditation to deal with pain. Many of them involve some form of distraction, placing your attention elsewhere. However, often our attention can be stuck focusing on the pain. In that case it can help to go with that and use the fact that every sensory experience, even pain, will vary from moment to moment.
This meditation technique help you reduce the perception of pain by paying selective attention to rapid and subtle decreases in the level of pain. At first the reductions are small and short, but with practice they will become larger and longer. As we practice this we train our brain to become better at reducing pain.
We tend to hold our bodies more tense than we need to and releasing that excess tension can help us relax and feel more comfortable. It can also help relieve pain, especially musculoskeletal pain.
To use this technique think of something soft and imagine one part of the body taking on that quality of softness more and more with each exhalation. After a few breaths pause and note how your body feels. Then either repeat that with the same part of the body, or allow a different part of the body to come to mind and let that part get softer for a few breaths. Continue to do this with various parts of your body shifting from one to another in a somewhat playful manner.